package com.lll.springbootkafka.kafka.bean.producer;

import com.alibaba.fastjson.JSONObject;
import com.lll.springbootkafka.kafka.bean.UserLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * Description: 消息生产者<br/>
 *
 * @author LLL<br               />;
 * @taskId <br/>
 * <br/>
 */
@Component
@Slf4j
public class UserLogProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    /**
     * 发送消息
     *
     * @param userId ：用户id
     */

    public void sendLogMsg(String userId) {
        UserLog userLog = new UserLog();
        userLog.setUserId(userId).setUserName("wjy").setState("0");
        System.err.println("发送用户日志信息：" + userLog);
        log.info("发送用户日志信息:{}", userLog);
        kafkaTemplate.send("user-log", JSONObject.toJSONString(log));
    }
}
